package com.cn.bulu.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cn.bulu.constant.PayMethod;
import com.cn.bulu.dao.WorkerWalletRecordDao;
import com.cn.bulu.pojo.WorkerWalletRecord;
import com.cn.bulu.service.WorkerWalletRecordService;
import com.cn.bulu.utils.DateUtils;
import com.cn.bulu.utils.LuKeOrderNoUtil;

@Service("workerWalletRecordService")
public class WorkerWalletRecordServiceImpl implements WorkerWalletRecordService {
	
	@Resource
	private WorkerWalletRecordDao workerWalletRecordDao;

	// 插入工人钱包数据库参数插入
	public int insertWorkerWalletRecord(Integer workerId, Integer indentId, Integer workerType, Double mainMoney,
			Double addMoney, Double subMoney, Double finalGetMoney, Double finalLostMoney, Double walletRecharge,
			Double walletWithdrawals, Integer type, Integer status, String remark, Integer isDelete, String method) {

		WorkerWalletRecord workerWalletRecord = getworkerWalletRecord(workerId, indentId, workerType, mainMoney,
				addMoney, subMoney, finalGetMoney, finalLostMoney, walletRecharge, walletWithdrawals, type, status,
				remark, isDelete, method);

		workerWalletRecordDao.insertWorkerWalletRecord(workerWalletRecord);
		return workerWalletRecord.getWorkerWalletRecordId() == null ? 0 : workerWalletRecord.getWorkerWalletRecordId();
	}

	// 插入数据库对象插入,并返回主键
	public int insertWorkerWalletRecord(WorkerWalletRecord workerWalletRecord) {
		workerWalletRecordDao.insertWorkerWalletRecord(workerWalletRecord);
		return workerWalletRecord.getWorkerWalletRecordId() == null ? 0 : workerWalletRecord.getWorkerWalletRecordId();
	}

	// 封装参数
	private WorkerWalletRecord getworkerWalletRecord(Integer workerId, Integer indentId, Integer workerType,
			Double mainMoney, Double addMoney, Double subMoney, Double finalGetMoney, Double finalLostMoney,
			Double walletRecharge, Double walletWithdrawals, Integer type, Integer status, String remark,
			Integer isDelete, String method) {
		// 参数准备
		WorkerWalletRecord workerWalletRecord = new WorkerWalletRecord();
		// 属性赋值
		workerWalletRecord.setWorkerId(workerId);// workerId 工人id
		workerWalletRecord.setIndentId(indentId == null ? null : indentId);// indentId
		workerWalletRecord.setWorkerType(workerType);// workerType 工人身份为2
		workerWalletRecord.setMainMoney(mainMoney == null ? 0.00 : mainMoney);// mainMoney 本次交易金额主干
		workerWalletRecord.setAddMoney(addMoney == null ? 0.00 : addMoney);// addMoney商家或者个人对订单进行加价悬赏
		workerWalletRecord.setSubMoney(subMoney == null ? 0.00 : subMoney); // subMoney商家或者个人违约扣款
		workerWalletRecord.setFinalGetMoney(finalGetMoney == null ? 0.00 : finalGetMoney);// finalGetMoney本次交易最终得到钱数
		workerWalletRecord.setFinalLostMoney(finalLostMoney == null ? 0.00 : finalLostMoney);// finalLostMoney本次交易最终失去金额
		workerWalletRecord.setWalletRecharge(walletRecharge == null ? 0.00 : walletRecharge); // walletRecharge充值金额
		workerWalletRecord.setWalletWithdrawals(walletWithdrawals == null ? 0.00 : walletWithdrawals);// walletWithdrawals提现
		workerWalletRecord.setType(type);// type 交易类型
		workerWalletRecord.setRecordEndTime(status == 1 ? DateUtils.getDateTime() : "");// recordEndTime交易结束时间
		workerWalletRecord.setRecordBeginTime(DateUtils.getDateTime()); // recordBeginTime交易开始时间
		workerWalletRecord.setStatus(status == 1 ? 1 : 0);// status
		workerWalletRecord.setRemark(remark);// remark交易备注
		workerWalletRecord.setIsDelete(isDelete == 1 ? 1 : 0);// isDelete
		workerWalletRecord.setMethod(method);// method
		workerWalletRecord.setOrderNo(LuKeOrderNoUtil.getWorkerOrderNo(workerId,PayMethod.getMethodIndex(method),type));// orderNo

		return workerWalletRecord;
	}

}
